/*
 * Copyright 2006 Brian Watkins
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package bw.util;

public class TimeDelta
{
    public long delta;
    public long hours;
    public long minutes;

    public TimeDelta ( long time1, long time2 )
    {
        delta = ( time1 - time2 ); 
        hours = ( delta / 1000 / 60 / 60 );
        minutes = ( delta / 1000 / 60 ) - ( hours * 60 );
    }

    public String toTimeString ()
    {
        StringBuffer buf = new StringBuffer();

        if ( this.delta < 60 * 1000 ) 
        {
            buf.append( "Just now" );
        }
        else if ( this.hours > 0 ) 
        {
            buf.append( this.hours ).append( " hour" );
            if ( this.hours > 1 ) { buf.append( "s" ); }
            if ( this.minutes > 0 ) 
            {
                buf.append( " " ).append( this.minutes ).append( " minute" );
                if ( this.minutes > 1 ) { buf.append( "s" ); }
            }
            buf.append( " ago" );
        }
        else
        {
            buf.append( this.minutes ).append( " minute" );
            if ( this.minutes > 1 ) { buf.append( "s" ); }
            buf.append( " ago" );
        }

        return buf.toString();
    }
}